#! /usr/bin/python

import math
def calculateN(a, b, c, d):
    part1 = set([a+b, a*b, a-b])
    if b != 0 : part1.add(a/float(b))
    part2 = set()
    for i in part1:
	part2.add(i+c)
	part2.add(i*c)
	part2.add(i-c)
        if c != 0: part2.add(i/float(c))
    part3 = set()        
    for i in part2:
	part3.add(i+d)
	part3.add(i*d)
	part3.add(i-d)
        if d != 0: part3.add(i/float(d))

    part11 = set([c+d, c*d, c-d])
    if d != 0 : part11.add(c/float(d))
    part22 = set()
    for i in part1:
	for j in part11:
	    part22.add(i+j)
	    part22.add(i*j)
	    part22.add(i-j)
            if j != 0: part22.add(i/j)    

    result = []
    for i in part3:
	if i > 0 and i - int(i) == 0: 
	   result.append(int(i))

    for i in part22:
	if i > 0 and i - int(i) == 0: 
	   result.append(int(i))

    return result

def permute(a, b, c, d):
    p = set()
    for i in (a, b, c, d):
	for j in (a, b, c, d):
	    if i == j: continue
	    for k in (a, b, c, d):
		if i == k or j == k: continue
		for l in (a, b, c, d):
		    if i == l or j == l or k == l: continue
		    p.add((i, j, k, l))
    return p

def maxN(result):
    new = []
    for i in result:
	if new.count(i) == 0:
           new.append(i)
    new.sort()
    #print new
    for i in range(1, len(new)):
	if new[i] - new[i-1] != 1: return new[i-1]

    return max(new)

result = []
pp = permute(1,2,3,4)
for (i, j, k, l) in pp:
    result.extend(calculateN(i, j, k, l))

print maxN(result)

mmax = 0
(ra, rb, rc, rd) = (0, 0, 0, 0)
for a in range(10):
    for b in range(a+1, 10):
	for c in range(b+1, 10):	    
	    for d in range(c+1, 10):
		p = permute(a, b, c, d)
		result = []
		for (i, j, k, l) in p:
		    result.extend(calculateN(i, j, k, l))
		l = maxN(result)
		if l > mmax: 
		   (ra, rb, rc, rd) = (a, b, c, d)	
		   mmax = l
print mmax, ra, rb, rc, rd

